Other places...
Assemply lessons
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8


Tools
Html Tester V 1.0
Code Encoder New

Vbcode
Under construction

Games
X & O الإصداره العربيه
X & O English Edition

Links
الفريق العربى
الموسوعه العربيه
شبكة فارس العامه
المطورون العرب
فجوال بيسك للعرب
الخبر كافيه
المهندس
www.vbzoom.com
Free vb codes
Linux for arabs
Free compilers
3alam el-computer
A good IT gate
www.ahliz.org


Mix
الدعاء
Site Packages
News(arabic)
My whispers
Site poles
About mrezzuz
Send feed-back

Ezzuz web site
Assemply 620/4/2003
(1)    The addressing technics :-

There is two : -

The logical address : -[segment : offset] such as [0080:0100h] ... this means that the address in the segment addressed by 80h and the offset into it is 0100h .

The physical address : - the real address of the operand .

how we calculate the physical address from the logical one ? : By multiply the segment adr. by 10h and add the offset to produse address with width 20 bit .

(2)    The addressing modes : -

Implied mode : -The operand is implied in the instruction it's self such as [hlt] witch no operand there.

Immediate mode : -The operand is writen it's self as a value such as [add AX,122Bh] .

Register mode : - The operand is within the register selected such as [ mov AX,20h --- add BX,AX ] .then the operand is the content of AX register.

Direct memory mode :- The operand is obtained from the memory addressed by the writen address such as [mov AX,[1223H] ] then the contant of mem. location 1223h is moved to AX .

Indirect memory mode : - The address of the operand in the mem is included in a register such as [ add BX,[SI] ] which the address in stack index is contain the operand .
And Note that : - The only possible registers can contain an address or can be used to operate with this mode is four registers : BX , SI , BP , DI .

(3)    Assemply main Instructions : -

[NOP] : - The prossor do nothing , use it if i want to wast one clock cycle without doing anything.

[HLT] : - Stop the cpu .

[INC] : - Increment the operand assigned after such as [INC AX ].

[ADD destination,source]: - destination= source + destination such as [ADD AX,CX ].

[SUB destination,source] :- destination= source - destination such as [SUB AX,CX ].

[MUL source] :- if the source is a byte then AX = byte * AL .

if the source is a word then DX:AX = WORD * AX .

[DIV SOURCE] :- if the source is byte then AL = AX/BYTE(quotiont) AND AH = AX%BYTE(reminder).

if the source is a word then AX = DX:AX / WORD(quotinot) AND DX = DX:AX % WORD(reminder).

[PUSH source] : - Push a source onto the top of the stack and increment the stack pointer such as [ PUSH AX ] .

[POP destination] : - Pop the top of the stack into the destination(must be a reg.) such as [ POP BX ] .

[INT ADDRESS] : - A system call witch calls the procedure in the address assign , such as [INT 21H ] .

[MOV source,destination] : - copy the contents of the destination into the source and note that the source and destination must have the same width bits such as [ MOV AX,[233FH] OR MOV AL,BYTE PTR [233FH] ] .


[CMP] : - Compares between two values by makeing a sub operation but may not change in the destination value , such as [CMP AX,1233H].,You use this instruction whenever check a value and you can obtain the following results:-

  • Greater than.
  • Less than.
  • Equal.
  • You also can test the flag register's bits (zero,sign,carry,over flow,....) by the jump instruction in section 8.

(4)    Define variabls : -
[var_name DB var_value] : - (define byte) to defina a var. called var_name has a value is var_value and have size=8bits such as [ var1 DB 30h ].

[var_name DW var_value] : - (define word) to defina a var. called var_name has a value is var_value and have size=16bits such as [ var2 DW 30h ].

[var_name DD var_value] : - (define double word) to defina a var. called var_name has a value is var_value and have size=32bits such as [ var3 DD 30h ].

[var_name DQ var_value] : - (define quad word ) to defina a var. called var_name has a value is var_value and have size=64bits such as [ var4 DQ 30h ].

[var_name DT var_value] : - (define ten) to defina a var. called var_name has a value is var_value and have size=10*8=80bits such as [ var5 DT 30h ].

Note that :-
- u must not assign a value to the variable but write insted ?.
- u can use the previous methods to define an array by insert many values in the var_value place such as [ array1 DB 45h,56h,'k',56h,?,?,45h,43h,60h,'$' ].

- u can also define string(array of characters) by many ways , see this [string db 'abcABC' -- string db 'inter a new value $ ' -- msg db 'hello',0ah,odh,'dfg','$' ] .

(5)    Some important things : -

[salary EQU 3000] : - used to assign a value to the const_name . then salary = 3000 whenever the whole program .

[LEA DX,var_name] : - Load effective address of the var name into DX , load the real address of the var in mem into DX (can use any 16-bit register) .

(6)    The general program structure : -
   .model small                        ;select the segment model by small model
   .stack 100h                        
   .DATA                               ;start the data segment 
       --------
       --------                        ;some variable definations and  EQU  statments .
       --------
       --------                        ;finish the data segment.

   .CODE                               ;start the code segment.
    MAIN PROC                          ;start the main procedure.
    MOV AX,@DATA                       ;initialize the data segment.
    MOV DS,AX
       --------
       --------
       --------
       --------
    MOV AH,4CH                         ; Exit to dos 
    INT 21h
    
    MAIN ENDP                          ;End the main

       --------
       --------                        ;other procedures
       --------
       --------

   ;Write the procedure that the program start running from it beside End .
    END MAIN                           
Note that :-

- All the above must writen in any assemply program except some changes ...

- The remarks after (;) is unlooked thing , it's just to understand you how the program flows .

(7)    Some important system calls : -

Input char :-

MOV AH,1H

INT 21h     ;The read key goes on AL


Output(print) char :-

MOV AH,2H

MOV DL,'?'      ; move the needed char into DL .

INT 21h


Print string :-

MOV AH,9H

LEA DX , VAR_MSG

INT 21h


Exit to dos :-

MOV AH,4CH

INT 21h


(8)    The jump instructions and loops : -

Unconditional jump : -

[JMP TARGET] jumb to the target (label) , U can use this kind in the containous loops.

Conditional jump : -


[JC TARGET] Jump to the target (label) If the carry flag is high(logic 1).

[JNC TARGET] Jump to the target (label) If the carry flag is low(logic 0).

[JZ TARGET] Jump to the target (label) If the zero flag is high(logic 1).

[JNZ TARGET] Jump to the target (label) If the zero flag is low(logic 0).

[JS TARGET] Jump to the target (label) If the sign flag is high(logic 1).

[JNS TARGET] Jump to the target (label) If the sign flag is low(logic 0).

[JO TARGET] Jump to the target (label) If the overflow flag is high(logic 1).

[JNO TARGET] Jump to the target (label) If the overflow flag is low(logic 0).

[JP TARGET] Jump to the target (label) If the parity flag is high(logic 1).

[JNP TARGET] Jump to the target (label) If the parity flag is low(logic 0).

And so on....



(9)    Notes : -

CALL INSTRUCTION calls a subrotain .

RET INSTRUCTION returns from a current subrotain .

[XOR AX,AX]  use to clear AX or AX=0(quick).

MOV [1223H],[8BFC] Invalid --> cann't move from mem to mem . Or cann't use a memory locations twice in one instruction .

To write a program and it(make it file.exe ) You can use the microsoft assembler and you can download it from here.

Book of the assemply : - There is a nice assemply referance here.

The fully instruction set of INTEL : - Also here.


I hope that this lesson was so easy and understandable , Ok if You want to Quary about any thing i'm waitting for You :-) .


Send feed-back to webmaster@1t.2t.3t.4t.com
Copy rights reserved to Ezzuz web site
22 / 3 / 2003
<<< Aseemply 5                         Assemply 6                         Assemply 7 >>>